//设备盘点
import React, { Component } from 'react';
import { Table, Button, Form, Card ,Divider, Tabs,Input,Row,Col,Checkbox,Drawer} from 'antd';
import '@/assets/css/settings';
import BasicForm from "../../components_yyr/common/basicForm";
import BasicDrawer from "../../components_yyr/common/basicDrawer";
import {FileDown,FileUpload} from "../../components_yyr/commponent/File";
import Paging from "../../components_yyr/commponent/Paging";
import BasicConfirm from "../../components_yyr/common/basicConfirm";
import TextArea from 'antd/lib/input/TextArea';
const { TabPane } = Tabs;
class App extends Component {
	state = {
		loading: false, //加载中...
		dataSource: [{p1:1111,p2:2222,p3:3333,p4:4444,p5:55555,p6:666666,type:0,remarks:'其他'}], //数据源
		drawerVisible: false,//新增修改抽屉的显示与隐藏
		chooseData: {},
		drawerTitle: '',
		visibleEquipment:false,
		total:0,
		formValues:{},
		cityData:[],
		mainFactoryList:[]
	};
	componentDidMount() {
		this.fetch({
			pageNum: 1,
			pageSize: 10
		});
		// this.getInfo();
	}
	//初始化加载数据
	fetch = (data) => {
		// this.setState({ loading: true })
		// this.post('/airCargo/pageList',{data}).then(res => {
		// 	this.setState({
		// 		loading: false,
		// 		dataSource: res.data.data,
		// 		total:res.data.total,
		// 		formValues:data
		// 	});
		// })
	}
	getInfo=()=>{
		this.post('/carrierPrice/mainFactoryList').then(res => this.setState({	mainFactoryList: res.data}))//主机厂
	}

	//表单查询
	filterSubmit = (values) => {
		values.pageNum = this.state.formValues.pageNum;
		values.pageSize = this.state.formValues.pageSize;
		this.fetch(values);
	};

	handleConfirm = (value, api,chooseData) => {
		if(api===1){
			this.get(`/airCargo/delAirCargo?id=${chooseData.id}`).then(res=>{
				this.success();
				this.fetch({...this.state.formValues});
			})
		}
		
	}

	formList = () => {
		const formList = [
			{				type: "SELECT", label: "盘点状态", field: "factoryName"		},
			{				type: "DATE", label: "计划盘点时间", field: "route" 	  }
		]
		return formList;
	};
	drawerFormList = data => {
		const {mainFactoryList}=this.state;
    const drawerFormList = [
		{
			type: "SELECT",
			label: "主机厂",
			field: "uniqueAddress",
			initialValue: data.uniqueAddress,
			list:mainFactoryList,
			valueField:'uniqueAddress',
			name:'mainFactoryName',
			required:true,
			
		},
		{
			type: "INPUT",
			label: "航线",
			field: "route",
			initialValue: data.route,
			required:true
		},
		{ type: "INPUTNUMBER",label: "港到港最低价",field: "harborMinimumPrice",initialValue:data.harborMinimumPrice,required:true},
		{ type: "INPUTNUMBER",label: "港到港100KG以下",field: "harborOneHundredPrice",initialValue:data.harborOneHundredPrice,required:true},
		{ type: "INPUTNUMBER",label: "港到港100KG-299kg",field: "harborTwoHundredPrice",initialValue:data.harborTwoHundredPrice,required:true},
		{ type: "INPUTNUMBER",label: "港到港300KG-999kg",field: "harborNineHundredPrice",initialValue:data.harborNineHundredPrice,required:true},
		{ type: "INPUTNUMBER",label: "港到港1T以上",field: "harborOneTonPrice",initialValue:data.harborOneTonPrice,required:true},
		{ type: "INPUTNUMBER",label: "门到门最低价",field: "doorMinimumPrice",initialValue:data.doorMinimumPrice,required:true},
		{ type: "INPUTNUMBER",label: "门到门100KG以下",field: "doorOneHundredPrice",initialValue:data.doorOneHundredPrice,required:true},
		{ type: "INPUTNUMBER",label: "门到门100KG-299kg",field: "doorTwoHundredPrice",initialValue:data.doorTwoHundredPrice,required:true},
		{ type: "INPUTNUMBER",label: "门到门300KG-999kg",field: "doorNineHundredPrice",initialValue:data.doorNineHundredPrice,required:true},
		{ type: "INPUTNUMBER",label: "门到门1T以上",field: "doorOneTonPrice",initialValue:data.doorOneTonPrice,required:true},
		{ type: "DATE",label: "门到门到达时间",field: "date_doorArrivalTime",initialValue:this.getDateByString(data.doorArrivalTime,'YYYY-MM-DD'),required:true},
		{ type: "INPUTNUMBER",label: "里程",field: "mileage",initialValue:data.mileage,required:true},
		{ type: "INPUTNUMBER",label: "专车费用",field: "specialBusFee",initialValue:data.specialBusFee,required:true},
		{ type: "DATE",label: "配送时间",field: "date_deliveryTime",initialValue:this.getDateByString(data.deliveryTime,'YYYY-MM-DD'),required:true},
		{ type: "TEXTAREA",label: "备注",field: "remarks",initialValue:data.remarks}
    ];
    return drawerFormList;
	};
	
	  // 提交modal
		handleSubmit = data => {
			const id = this.state.chooseData && this.state.chooseData.id;
			if (id) {
				data=Object.assign({}, data,{id:id });
				data.updateId=localStorage.getItem('userId');
			}else{
				data.createId=localStorage.getItem('userId');
			}
			this.post('/airCargo/addAirCargo',{data}).then(res=>{
				this.success();
				this.fetch({...this.state.formValues});
				this.onClose();
			})
			
		};

			// 打开modal，判断是修改还是新增 0新增 1修改
		handleModal = (type,data ) => {
			if (type) {
				this.setState({
					drawerTitle: "修改",
					visibleEquipment: true,
					chooseData:data
				});
			} else {
					this.setState({
					drawerTitle: "新增",
					visibleEquipment: true,
				});
			}
		};


		onClose=()=>{
			
			this.setState({
				visibleEquipment: false,
				chooseData: {}
			});
			// this.modalRef.props.form.resetFields();
		}


	render() {
		const columns = [
			{
				title: '单号',
				dataIndex: 'p1',
			},
			{
				title: '计划盘点时间',
				dataIndex: 'p2',
			},
			{
				title: '盘点人',
				dataIndex: 'p3',
			},
			{
				title: '部门名称',
				dataIndex: 'p4',
			},
			{
				title: '设备类型',
				dataIndex: 'p5',
			},
			{
				title: '剩余未盘数',
				dataIndex: 'p6',
			},
            {
				title: '处理状态',
				dataIndex: 'type',
                render:(text,record)=>{
                    if(text===0){
                        return <span>待盘点</span>
                    }if(text===1){
                        return <span>已盘点</span>
                    }
                }
			},
			{
				title: '备注',
				dataIndex: 'remarks',
			},
			
			{
				title: '操作',
				width:'12%',
				render: (text, record) => {
					return	<span>
                        <a href onClick={()=>this.handleModal(1,record)}>盘点</a>
						<Divider type="vertical" />
						<a href onClick={()=>this.handleModal(1,record)}>修改</a>
						<Divider type="vertical" />
						<BasicConfirm title='确认删除?'api={1} button={false} buttonName='删除' data={record}  handleConfirm={this.handleConfirm}/>
					</span>
				}
			}
		];

		const {chooseData,drawerVisible,drawerTitle,dataSource,loading,total,formValues}=this.state;
	
		const drawerProps={
			onRef:(ref)=>this.modalRef=ref,visible:drawerVisible,width:700,drawerFormList:this.drawerFormList(chooseData),
			submit:this.handleSubmit,onClose:this.onClose,title:drawerTitle
		}
		const formItemLayout = {
			labelCol: {
					xs: {span: 24},
					sm: {span: 6},
			},
			wrapperCol: {
					xs: {span: 24},
					sm: {span: 18},
			},
		};
		const options = [
			{ label: '重点设备', value: '1' },
			{ label: '主要设备', value: '2' },
			{ label: '一般设备', value: '3' },
			{ label: '其他', value: '4' },
		  ];
		const {getFieldDecorator} = this.props.form;
		return (
			<div className="shadow-radius">
				<Card><BasicForm formList={this.formList()} filterSubmit={this.filterSubmit} labelSpan={8} wrapperSpan={12} onRef={(ref) => this.child = ref} /></Card>
				
                <Tabs tabBarExtraContent={<div className="buttonList">
                        <Button icon="plus" onClick={()=>this.handleModal(0,{})} type="primary"> 新增</Button>
                        <FileDown fileName='设备盘点模板' buttonName='模板下载' apiPath='/airCargo/carrierPriceExcel'/>
                        <FileDown fileName='设备盘点清单' buttonName='导出' method='post' apiPath='/airCargo/exportCarrierPriceDataExcel' data={formValues}/>
                        <FileUpload buttonName='导入' apiPath='/airCargo/carrierPriceExcel' load={true} fetch={()=>this.fetch({...formValues})}/>
                    </div>}>
                    <TabPane tab='设备盘点' key='1'>
                        <Table columns={columns} rowKey={(record, index) => index} dataSource={dataSource} pagination={false}	loading={loading} scroll={{y:500}} 	/>
                        <Paging total={total} formValues={formValues} fetch={(pager)=>this.fetch(pager)}/>
                    </TabPane>
                </Tabs>
				
                <Tabs>
                    <TabPane tab='盘点明细' key='1'>
                    <Table columns={columns} rowKey={(record, index) => index} dataSource={dataSource} pagination={false}	loading={loading} scroll={{y:500}} 	/>
                    </TabPane>
                    <TabPane tab='操作记录' key='2'>
                    <Table columns={columns} rowKey={(record, index) => index} dataSource={dataSource} pagination={false}	loading={loading} scroll={{y:500}} 	/>
                    </TabPane>
                </Tabs>
                <Drawer
				width='1200px'
				title={this.state.drawerTitle}
				placement="right"
				onClose={this.onClose}
				visible={this.state.visibleEquipment}
				>
				<h3 style={{fontWeight:'bold'}}>盘点信息</h3>
				<Form  {...formItemLayout} layout='horizontal' style={{paddingLeft:30,paddingTop:0}}>
					
					<Row style={{paddingLeft:'15px'}}>
						<Col span={22} style={{width:'24%'}}>
							<Form.Item label={'盘点单号'} style={{marginBottom:5}}>
								{getFieldDecorator('workshopId',{})(
								<Input style={{width:200}} />
								
						)}
							</Form.Item>
						</Col>
						
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'盘点名称'} style={{marginBottom:5}}>
								{getFieldDecorator('lineId',{})(
								<Input />
								
								)}
							</Form.Item>
						</Col>
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'计划盘点时间'} style={{marginBottom:5}}>
								{getFieldDecorator('workshopId',{})(
								<Input />
								
						)}
							</Form.Item>
						</Col>
						
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'设备类别'} style={{marginBottom:5}}>
								{getFieldDecorator('lineId',{})(
								<Input />
								
								)}
							</Form.Item>
						</Col>
					</Row>
					<Row style={{paddingLeft:'15px'}}>
						<Col span={22} style={{width:'24%'}}>
							<Form.Item label={'盘点部门'} style={{marginBottom:5}}>
								{getFieldDecorator('teamName')(<Input placeholder='请输入班组名称' />)}
							</Form.Item>
						</Col>
						
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'盘点人'} style={{marginBottom:5}}>
								{getFieldDecorator('teamNum')(
								
								<Input />
								)}
							</Form.Item>
						</Col>
						
					</Row>
					<Row style={{paddingLeft:'15px'}}>
						<Col span={22} style={{width:'24%'}}>
							<Form.Item label={'资产原值'} style={{marginBottom:5}}>
								{getFieldDecorator('teamName')(<Input placeholder='请输入班组名称' />)}
							</Form.Item>
						</Col>
						
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'资产净值'} style={{marginBottom:5}}>
								{getFieldDecorator('teamNum')(
								
								<Input />
								)}
							</Form.Item>
						</Col>
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'资产负责人'} style={{marginBottom:5}}>
								{getFieldDecorator('teamName')(<Input placeholder='请输入班组名称' />)}
							</Form.Item>
						</Col>
						
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'要求验收时间'} style={{marginBottom:5}}>
								{getFieldDecorator('teamNum')(
								
								<Input />
								)}
							</Form.Item>
						</Col>
					</Row>
					<Row style={{}}>
						<Col span={10} style={{width:'30%'}}>
							<Form.Item label={'设备标记'} style={{marginBottom:5}}>
								{getFieldDecorator('teamName')(
								<Checkbox.Group style={{width:'355px'}} options={options} />
								)}
							</Form.Item>
						</Col>
						
					</Row>
					<h3 style={{fontWeight:'bold',marginLeft:'-30px'}}>使用状况</h3>
					<Row style={{paddingLeft:'15px'}}>
						<Col span={22} style={{width:'24%'}}>
							<Form.Item label={'使用状况'} style={{marginBottom:5}}>
								{getFieldDecorator('workshopId',{})(
								<Input style={{width:200}} />
								
						)}
							</Form.Item>
						</Col>
						
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'使用部门'} style={{marginBottom:5}}>
								{getFieldDecorator('lineId',{})(
								<Input />
								
								)}
							</Form.Item>
						</Col>
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'操作人'} style={{marginBottom:5}}>
								{getFieldDecorator('workshopId',{})(
								<Input />
								
						)}
							</Form.Item>
						</Col>
						
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'维修组'} style={{marginBottom:5}}>
								{getFieldDecorator('lineId',{})(
								<Input />
								
								)}
							</Form.Item>
						</Col>
					</Row>
					<Row style={{paddingLeft:'15px'}}>
						<Col span={22} style={{width:'24%'}}>
							<Form.Item label={'租用单位'} style={{marginBottom:5}}>
								{getFieldDecorator('workshopId',{})(
								<Input style={{width:200}} />
								
						)}
							</Form.Item>
						</Col>
						
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'设备位置'} style={{marginBottom:5}}>
								{getFieldDecorator('lineId',{})(
								<Input />
								
								)}
							</Form.Item>
						</Col>
						
					</Row>
					<h3 style={{fontWeight:'bold',marginLeft:'-30px'}}>扩展字段</h3>
					<Row style={{paddingLeft:'15px'}}>
						<Col span={22} style={{width:'24%'}}>
							<Form.Item label={'固定资产编号'} style={{marginBottom:5}}>
								{getFieldDecorator('workshopId',{})(
								<Input style={{width:200}} />
								
						)}
							</Form.Item>
						</Col>
						
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'文本2'} style={{marginBottom:5}}>
								{getFieldDecorator('lineId',{})(
								<Input />
								
								)}
							</Form.Item>
						</Col>
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'文本3'} style={{marginBottom:5}}>
								{getFieldDecorator('workshopId',{})(
								<Input />
								
						)}
							</Form.Item>
						</Col>
						
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'文本4'} style={{marginBottom:5}}>
								{getFieldDecorator('lineId',{})(
								<Input />
								
								)}
							</Form.Item>
						</Col>
					</Row>
					<Row style={{paddingLeft:'15px'}}>
						<Col span={22} style={{width:'24%'}}>
							<Form.Item label={'文本5'} style={{marginBottom:5}}>
								{getFieldDecorator('workshopId',{})(
								<Input style={{width:200}} />
								
						)}
							</Form.Item>
						</Col>
						
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'文本6'} style={{marginBottom:5}}>
								{getFieldDecorator('lineId',{})(
								<Input />
								
								)}
							</Form.Item>
						</Col>
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'文本7'} style={{marginBottom:5}}>
								{getFieldDecorator('workshopId',{})(
								<Input />
								
						)}
							</Form.Item>
						</Col>
						
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'文本8'} style={{marginBottom:5}}>
								{getFieldDecorator('lineId',{})(
								<Input />
								
								)}
							</Form.Item>
						</Col>
					</Row>
					<Row style={{paddingLeft:'15px'}}>
						<Col span={22} style={{width:'24%'}}>
							<Form.Item label={'文本9'} style={{marginBottom:5}}>
								{getFieldDecorator('workshopId',{})(
								<Input style={{width:200}} />
								
						)}
							</Form.Item>
						</Col>
						
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'已经'} style={{marginBottom:5}}>
								{getFieldDecorator('lineId',{})(
								<Input />
								
								)}
							</Form.Item>
						</Col>
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'数字型'} style={{marginBottom:5}}>
								{getFieldDecorator('workshopId',{})(
								<Input />
								
						)}
							</Form.Item>
						</Col>
						
						<Col span={22} style={{width:'24%',paddingLeft:10}}>
							<Form.Item label={'启用时间'} style={{marginBottom:5}}>
								{getFieldDecorator('lineId',{})(
								<Input />
								
								)}
							</Form.Item>
						</Col>
					</Row>
					<Row style={{paddingLeft:'15px'}}>
						<Col span={22} style={{width:'24%'}}>
							<Form.Item label={'备注'} style={{marginBottom:5}}>
								{getFieldDecorator('workshopId',{})(
								// <Input style={{width:200}} />
								<TextArea style={{width:'600px'}}  />
						)}
							</Form.Item>
						</Col>
	
					</Row>
					
					<h3 style={{fontWeight:'bold',marginLeft:'-30px'}}>关联图片</h3>
				</Form>
					<div className="drawer_foot">
					<Button onClick={this.onClose} style={{ marginRight: 8 }}>取消</Button>
					<Button onClick={()=>this.submitAddEditTeam()} type="primary">确定</Button>
					</div>
				</Drawer>
				<BasicDrawer	{...drawerProps} />

			</div>
		);
	}
}
export default Form.create()(App);